package com.sino.report;

import java.awt.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

public class CellStyle {
	private int border = -1;

	private int borderWidthLeft = -1;
	private int borderWidthRight = -1;
	private int borderWidthTop = -1;
	private int borderWidthBottom = -1;

	private java.awt.Color bordercolor = null;
	private java.awt.Color backgroudColor = null;
	private java.awt.Color color = null;

	private int size = -1;
	private boolean underlined;
	private boolean italic;
	private boolean bold;
	private String align = null;
	private String valign = null;
	private String name;
	private String height;
	private String width;
	private String image;
	private String id;

	public CellStyle() {
	}

	public String load(NodeList node) {
		String strTemp = null;
		try {
			for (int m = 0; m < node.getLength(); m++) {
//      Element student = (Element) node.item(m);
//      student.getAttribute("id");
				if (node.item(m).getChildNodes().getLength() > 0) {
					strTemp = node.item(m).getChildNodes().item(0).getNodeValue();
				} else {
					strTemp = "";
				}
				if (node.item(m).getNodeName().equals("id")) {
					id = strTemp;
				} else if (node.item(m).getNodeName().equals("align")) {
					align = strTemp;
				} else if (node.item(m).getNodeName().equals("italic")) {
					italic = strTemp.equals("true");
				} else if (node.item(m).getNodeName().equals("border")) {
					border = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("height")) {
					height = strTemp;
				} else if (node.item(m).getNodeName().equals("width")) {
					width = strTemp;
				} else if (node.item(m).getNodeName().equals("valign")) {
					valign = strTemp;
				} else if (node.item(m).getNodeName().equals("borderWidthLeft")) {
					borderWidthLeft = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("borderWidthRight")) {
					borderWidthRight = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("borderWidthTop")) {
					borderWidthTop = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("borderWidthBottom")) {
					borderWidthBottom = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("bordercolor")) {
					if (strTemp.indexOf("#") > -1) {
						strTemp = strTemp.substring(strTemp.indexOf("#") + 1);
					}
					strTemp = Tools.stringFormat(strTemp, 6);

					bordercolor = new Color(Integer.parseInt(strTemp.
						substring(0, 2), 16),
											Integer.parseInt(strTemp.
						substring(2, 4), 16),
											Integer.parseInt(strTemp.
						substring(4, 6), 16));
				}

				else if (node.item(m).getNodeName().equals("bgcolor")) {
					if (strTemp.indexOf("#") > -1) {
						strTemp = strTemp.substring(strTemp.indexOf("#") + 1);
					}
					strTemp = Tools.stringFormat(strTemp, 6);

					backgroudColor = new Color(Integer.parseInt(strTemp.
						substring(0, 2), 16),
											   Integer.parseInt(strTemp.
						substring(2, 4), 16),
											   Integer.parseInt(strTemp.
						substring(4, 6), 16));

				}

				else if (node.item(m).getNodeName().equals("color")) {
					if (strTemp.indexOf("#") > -1) {
						strTemp = strTemp.substring(strTemp.indexOf("#") + 1);
					}
					strTemp = Tools.stringFormat(strTemp, 6);

					color = new Color(Integer.parseInt(strTemp.
						substring(0, 2), 16),
									  Integer.parseInt(strTemp.
						substring(2, 4), 16),
									  Integer.parseInt(strTemp.
						substring(4, 6), 16));

				} else if (node.item(m).getNodeName().equals("size")) {
					size = Integer.parseInt(strTemp);
				} else if (node.item(m).getNodeName().equals("name")) {
					name = strTemp;
				} else if (node.item(m).getNodeName().equals("underlined")) {
					underlined = (strTemp).equalsIgnoreCase("true");
				} else if (node.item(m).getNodeName().equals("bold")) {
					bold = (strTemp).equalsIgnoreCase("true");
				}
			}
		} catch (NumberFormatException ex) {
			ex.printStackTrace();
		} catch (DOMException ex) {
			ex.printStackTrace();
		}
		return id;
	}

	public String getAlign() {
		return align;
	}

	public int getBorder() {
		return border;
	}

	public String getHeight() {
		return height;
	}

	public String getValign() {
		return valign;
	}

	public String getWidth() {
		return width;
	}

	public java.awt.Color getBordercolor() {
		return bordercolor;
	}

	public java.awt.Color getBackgroudColor() {
		return backgroudColor;
	}

	public java.awt.Color getColor() {
		return color;
	}

	public int getSize() {
		return size;
	}

	public String getName() {
		return name;
	}

	public boolean isBold() {
		return bold;
	}

	public boolean isItalic() {
		return italic;
	}

	public boolean isUnderlined() {
		return underlined;
	}

	public int getBorderWidthLeft() {
		return borderWidthLeft;
	}

	public int getBorderWidthRight() {
		return borderWidthRight;
	}

	public int getBorderWidthTop() {
		return borderWidthTop;
	}

	public int getBorderWidthBottom() {
		return borderWidthBottom;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
